<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <p>接收到b页面传来的值：<span id="data"></span></p>
  <script>
    function proxy(url, callback) {
      var state = 0
      var iframe = document.createElement('iframe')
      iframe.src = url
      iframe.style.display = 'none'
      // onload方法会执行两次，第一次加载跨域页面，第二次加载同步页面
      iframe.onload = function() {
        if (state === 0) {
          // contentWindow可以读取子页面里面的文档
          iframe.contentWindow.location = 'http://www.cross.com:3000/name/agent.html'
          state = 1
        } else if (state === 1) {
          callback(iframe.contentWindow.name)
          clearIframe()
        }
      }
      document.body.appendChild(iframe)

      function clearIframe() {
        iframe.contentWindow.document.write('')
        iframe.contentWindow.close()
        document.body.removeChild(iframe)
      }
    }

    proxy('http://child.cross.com:3000/name/b.html', function(data) {
      console.log(data)
      document.getElementById('data').innerText = data
    })
  </script>
</body>
</html>